<?php
namespace Common\Model;
use Think\Model;

class  ArticleModel extends  Model{
	private $table = 'article'; //指定表名
	
	/**
	 * 获得所有的数据
	 */
	public function getData(){
		
		$data = I('post.');
		$page = $data['page'];
		$pageSize = $data['rows'];
		$first = $pageSize * ($page-1);
		$order = $data['order'];
		$sort = $data['sort'];
		//获得总条数
		$total = $this->count();
		//获得数据
		$getData = $this->field('article_id,article_title,article_thumb,article_author,article_time,article_pv')->order(" article_id $order " )->limit("$first,$pageSize")->select();
//		var_dump($this->getLastSql());
		$allData['total'] = $total;
		$allData['rows'] = $getData ;
		return $allData; 
	}
	
	/**
	 * 获得关联的文章
	 */
	public function selectData($where,$limit=null){
		$data = $this->join('lm_article_data on lm_article.aid = lm_article_data.aid ')->field('lm_article.aid,title,thumb,desc,tag')->where($where)->limit($limit)->select();
		return $data;
	}
	
}